package org.speedmall.core.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.speedmall.core.service.ProductService;
import org.speedmall.storage.api.bo.ProductDecreaseBO;
import org.speedmall.storage.api.bo.ProductIncreaseBO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author hujiaguo
 * @Package org.speedmall.core.controller
 * @date 2024/4/25 18:29:16
 */
@Api(tags = "产品")
@Slf4j
@RestController
@RequestMapping("product")
public class ProductController {

    @Autowired
    private ProductService productService;

    @ApiOperation("增加数量")
    @PostMapping("increase")
    public void increase(@RequestBody ProductIncreaseBO bo) {
        log.info("库存服务：增加产品库存。productId: {}, count: {}", bo.getProductId(), bo.getCount());
        productService.increaseStorage(bo);
    }

    @ApiOperation("扣减数量")
    @PostMapping("decrease")
    public void decrease(@RequestBody ProductDecreaseBO bo) {
        log.info("库存服务：减少产品库存。productId: {}, count: {}", bo.getProductId(), bo.getCount());
        productService.decreaseStorage(bo);
    }
}
